﻿using System.Collections.Generic;
using System.Linq;

namespace MyBasicLib.Data.ORMLiteNew
{
    public sealed class DbQueryable<TSource> : IDbQueryable<TSource>
    {
        #region Ctor

        internal DbQueryable(  IDbQueryProvider provider)
            : this(  provider, null)
        {
        }

        internal DbQueryable(  IDbQueryProvider provider,
                             IEnumerable<DbExpression> dbExpressions)
        {
            //Check.Argument.IsNotNull(dataContext, "dataContext");
            Check.Argument.IsNotNull(provider, "provider");
            DbProvider = provider;
           // DataContext = dataContext;
            if (dbExpressions == null || !dbExpressions.Any(p => p.DbExpressionType == DbExpressionType.Source))
            {
                _dbExpressions.Add(
                    new SourceDbExpression(this));
            }
            if (dbExpressions != null)
            {
                _dbExpressions.AddRange(dbExpressions);
            }
        }

        #endregion

        #region Implementation of IDbQueryable<T>

        private readonly List<DbExpression> _dbExpressions = new List<DbExpression>()
                                            ;


        public IDbQueryProvider DbProvider { get; private set; }

        public IList<DbExpression> DbExpressions
        {
            get { return _dbExpressions; }
        }

        //public IDataContext DataContext { get; private set; }

        #endregion

        //public TSource Execute()
        //{
        //    this.DataContext.
        //    return DbProvider.Executor.Execute<TSource>(this);
        //}

        //public List<TSource> ExecuteList()
        //{
        //    return DbProvider.Executor.ExecuteList<TSource>(this);
        //}
    }
}